<?php
/**
 * 处理用户的登录请求
 *
 */
require_once( './path.php' );

//调用初始化页面
require_once( CLASSMATE_ROOT.'/controller/process_script_init.php' );

@$request = $_POST;

try{

if ( session::get( 'is_online' ) ){
//已经登录成功，无需再进行登录操作，重定向到response_message页面
	 $response_message = array(
			 'type' => 'info' , 
			 'content' => '已经登录系统' ,
			 'url_des'=>'返回首页？' ,
			 'url' => '/classmate/controller/index.php' );
			 
	 session::set( 'response_message' , $response_message );

	 header( 'Location: ../response_message.php' );
	 exit();
}

$db_connect = mongo_connect();
$user_auth_process = new user_auth_process( $db_connect );

if ( $user_auth_process->do_login( $request ) ){
//登录成功
	
	 $response_message = array( 'type'=>'success' , 
	 		'content'=>'登录成功' ,
	 		'url_des'=>'返回首页' ,
	 		'url'=>'/classmate/controller/index.php' );
	 		
	 session::set( 'response_message' , $response_message );
	 header( 'Location: ../response_message.php' );
	 exit();
}else{
//无法预料的登录失败
	
	throw new Exception( '无法预料原因的登录失败' );

}

}catch( Exception $e ){

	$login_fail_message = array( 'type'=>'error' , 'content'=>$e->getMessage() , 'url'=>'../../index.php' );

	session::set( 'login_fail_message' , $login_fail_message );
	header( 'Location: login.php' );
	exit();
}


